<!DOCTYPE html>
<html>
<head>


    <link rel="stylesheet" href="/Statics/Home/css/amazeui.min.css">
    <link rel="stylesheet" href="/Statics/Home/css/reset.css">
    <link rel="stylesheet" href="/Statics/Home/css/common.css">
    <link rel="stylesheet" href="/Statics/Home/css/button.css">

    <link rel="stylesheet" href="/Statics/Home/js/sco/css/scojs.css" />
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_g6sy031jy4zbmx6r.css" />
    <template file="Home/meta" />
    <template file="Home/css" />






</head>
<body style="background:#fafafc">





<if condition="$cartlist[num]">

    <div class="base" >


    <div class=" am-g   am-padding-vertical-sm common-border-bottom   am-text-000" data-am-sticky>
        <div class="am-u-sm-6  " >

            <label class="am-checkbox-inline" >
                <input type="checkbox" class="check-all "  checked value="" data-am-ucheck> &nbsp; 全选
            </label>


        </div>

        <div class="am-u-sm-6 am-text-right  " >

            <a href="{:U('cart_dell')}" class="ajax-get am-text-danger">清空</a>


        </div>

    </div>

    <form method="post" class="form-horizontal check_form" action='{:U("User/Order/check")}'>

        <div class="am-cf  am-padding-0 ">


            <volist name="cartlist.data" id="v">

                <div class="  am-g cart-list-item     common-border-bottom am-padding-vertical-sm ">


                    <div class="am-u-sm-1 am-text-center">
                        <label class="am-checkbox-inline">
                            <input type="checkbox" checked class="ids" name="product_id[]"  value="{$v.id}" data-am-ucheck>
                        </label></div>
                    <div class="am-u-sm-4 am-text-center  list_img"><img src="{$v.thumb}" class="am-img-responsive"></div>
                    <div class="am-u-sm-7 am-text-xs am-padding-left-0">




                        <a href="{:U('Home/Product/show',array('id'=>$v['id']))} " class="">
                            <h3 class="am-margin-0">
                                {$v.title}</h3>
                        </a>

                        <div class="am-cf am-text-sm">

                            <span class="am-u-sm-12 am-text-danger"> ￥ <span class="auto_price">{$v.price}</span></span>
                            <span class="am-u-sm-12 am-text-right">

                              <div class="am-input-group  am-input-group-xs am-text-xs">
                                <span class="am-input-group-btn jian" data-id="{$v.id}">
                                <button class="am-btn am-btn-xs am-btn-default  " type="button">
                                    <span class="am-icon-minus" ></span></button>
                                </span>
                                  <input type="text" min="0" name="product[{$v.id}]"
                                         class="am-form-field am-input-xs auto_num  am-text-center"
                                         style="background: #fff" readonly value="{$v.num}" min="0"
                                         max="999" maxlength="3">



                                <span class="am-input-group-btn jia" data-id="{$v.id}">
                                <button class="am-btn am-btn-default am-btn-xs " type="button">
                                    <span class="am-icon-plus" ></span></button>
                                </span>
                              </div>
                            </span>



                        </div>







                    </div>


                </div>

            </volist>



        </div>





    </form>



    </div>




<else/>



    <div class=" am-text-center  am-margin-vertical-lg am-padding-vertical-lg">


        <p>购物车块饿瘪了T.T</p>
        <p>快给我挑点宝贝吧</p>


        <a href="/" class=" btn-write am-padding-xs am-padding-horizontal-lg">去逛逛</a>


    </div>


    </if>




<div data-am-widget="navbar" class="am-navbar am-cf am-navbar-index  common-border-top "
     style="height: 107px;">
    <div class="order-from-bottom am-text-right common-border-bottom " style="position:relative">

        <span class="am-margin-right-sm"> 合计： <span class="am-text-f60  heji ">￥{$cartlist.price_sum}</span></span>


        <button    class="am-btn  am-btn-danger am-btn-xl  ajax-post btn-jiesuan" target-form="check_form" type="submit"   >结算</button>





    </div>
    <template file="Home/bottom_nav" />
</div>





<template file="Home/js" />

<script>


    $(function(){

        $("#edit_btn").click(function(){


            $(".base").hide();
            $(".edit").show();

            $('.btn-jiesuan').hide();


        })
    })



    $(document).on("click",".cart-del",function(){

        var that=$(this);


        $.ajax({
            type: "GET",
            url: $(this).attr('href'),
            data: "att="+$(this).data('href'),
            success: function(data){


                if (data.status == '1') {
//                    $.scojs_message(data.info, $.scojs_message.TYPE_OK);

                    that.parents(".cart-list-item").remove();


                    s_check();
                }else{

                    $.scojs_message(data.info, $.scojs_message.TYPE_ERROR);
                }

            }

        });

        return false;

    });


    $(function(){






        $(".jia").click(function(){
            var input=$(this).prev(".auto_num");
            var n=input.val();

            $.post("{:U('jia')}", { id: $(this).data("id") }, function (data) {
            if(data.status){
                var num=parseInt(n)+1;

                input.val(num);
                s_check();

            }

            })

        });

        //减的效果
        $(".jian").click(function(){
            var input=$(this).next(".auto_num");
            var n=input.val();


            that=$(this);


            $.post("{:U('jian')}", { id: $(this).data("id") }, function (data) {

                if(data.status){
                    var num=parseInt(n)-1;
                    if(num==0){


                        that.parents(".cart-list-item").remove();

                    }
                    input.val(num);
                    s_check();

                }

            })


        });





    })



    function  s_check(){
        var sum=0;
        var sum_price=0;




        $(".check_form .cart-list-item ").each(function(){




            num=$(this).find(".auto_num").val()







            price=$(this).find(".auto_price").html()



            price=parseFloat(price).toFixed(2);



            $num=parseInt(num);


            sum_price=sum_price+price*num;


        })



        $(".heji").html("￥:"+sum_price);



    }


</script>

</body>
</html>